package se.webbzon.oschi01.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Tunnel implements Reader<OutputStream,InputStream> {
	
	private static final int bufferSize = 4096;
	
	private final OutputStream os;
	
	public Tunnel(OutputStream os) {
		this.os = os;
	}

	@Override public OutputStream read(InputStream source) throws IOException {
		byte[] buffer = new byte[bufferSize];
		int length = source.read(buffer);
		while (length != -1) {
			os.write(buffer, 0, length);
			length = source.read(buffer);
		}
		return os;
	}

}
